﻿using System.IO;
using System.Text;
using HtmlAgilityPack;

namespace Mvc.RazorTools.Tests
{
	/// <summary>
	/// This object inherits from the abstract class MvcRazorObject
	/// in order to unit test the class.
	/// </summary>
	public class TestObject : MvcRazorObject
	{
		public static class TestConstants
		{
			public const string IdName = "id";
			public const string IdValue = "TestId";
			public const string Name = "TestName";
			public const string HtmlTag = "span";
		}

		public TestObject()
			: base()
		{
		}

		public TestObject(string id)
			: base(id)
		{
		}

		protected override string OnInitializeId()
		{
			return TestConstants.IdValue;
		}

		protected override string OnInitializeName()
		{
			return TestConstants.Name;
		}

		protected override string OnInitializeHtmlTag()
		{
			return TestConstants.HtmlTag;
		}

		public HtmlNode HtmlNode()
		{
			return this.HtmlNode(this.Html.ToString());
		}

		public HtmlNode HtmlNode(string html)
		{
			HtmlDocument returnValue = new HtmlDocument();

			byte[] data = ASCIIEncoding.ASCII.GetBytes(html);
			using (MemoryStream io = new MemoryStream(data))
			{
				returnValue.Load(io);
				io.Close();
			}

			return returnValue.DocumentNode.ChildNodes[0]; ;
		}
	}
}
